/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Bus_合同分拆报工",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.Order.IServices;
using VOL.Core.Utilities;
using VOL.Entity.dtomodel;
using System.ServiceModel.Channels;
using Newtonsoft.Json;

namespace VOL.Order.Controllers
{
    public partial class Bus_合同分拆报工Controller
    {
        private readonly IBus_合同分拆报工Service _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Bus_合同分拆报工Controller(
            IBus_合同分拆报工Service service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        //[HttpPost]
        //[Route("ZiJianShuTongSubmitNotFinish")]
        //public ActionResult ZiJianShuTongSubmitNotFinish([FromBody] Bus_合同分拆报工DTO 合同分拆报工dtos)
        //{
        //    VOL.Core.Services.Logger.Info("ZiJianShuTongSubmitNotFinish收到" + JsonConvert.SerializeObject(合同分拆报工dtos));
        //    WebResponseContent webResponse = new WebResponseContent();
        //    string message = "";
        //    var a = _service.ZiJianShuTongSubmitNotFinish(合同分拆报工dtos, ref message);
        //    webResponse.OK(message);
        //    return Json(webResponse);
        //}

        //[HttpPost]
        //[Route("ZiJianShuTongSubmitFinished")]
        //public ActionResult ZiJianShuTongSubmitFinished([FromBody] Bus_合同分拆报工DTO 合同分拆报工dtos)
        //{
        //    WebResponseContent webResponse = new WebResponseContent();
        //    string message = "";
        //    var a = _service.ZiJianShuTongSubmitFinished(合同分拆报工dtos,ref message);
        //    if (a > 0)
        //    {
        //        webResponse.OK(message);
        //    }
        //    else
        //    {
        //        webResponse.Error(message);
        //    }

        //    return Json(webResponse);
        //}

        #region 自建报工

        [HttpPost]
        [Route("ZiJianShuTongSubmit")]
        public ActionResult ZiJianShuTongSubmit([FromBody] Bus_合同分拆报工DTO 合同分拆报工dtos)
        {
            VOL.Core.Services.Logger.Info("1班组提交报工,请求:" + JsonConvert.SerializeObject(合同分拆报工dtos));

            WebResponseContent webResponse = new WebResponseContent();
            string message = "";
            var a = _service.ZiJianShuTongSubmit(合同分拆报工dtos);
            VOL.Core.Services.Logger.Info("3班组提交报工,返回结果:" + JsonConvert.SerializeObject(a));
            //if (a > 0)
            //{
            //    webResponse.OK(message);
            //}
            //else
            //{
            //    webResponse.Error(message);
            //}

            return Json(a);
        }

        [HttpPost]
        [Route("GetBanZuYiBaoGongList")]
        public ActionResult GetBanZuYiBaoGongList([FromBody] Bus_合同分拆报工 bus_合同分拆报工)
        {
            VOL.Core.Services.Logger.Info("1班组查询已报工,请求:" + JsonConvert.SerializeObject(bus_合同分拆报工));

            WebResponseContent webResponse = new WebResponseContent();
            string message = "";
            var bus_合同分拆报工List = _service.GetBanZuYiBaoGongList(bus_合同分拆报工);
            
            if (bus_合同分拆报工List != null && bus_合同分拆报工List.Count > 0)
            {
                webResponse.Code = "0";
                webResponse.Data = bus_合同分拆报工List;
            }
            else
            {
                webResponse.Code = "1";
                webResponse.Message = "未查询到数据";
            }
            VOL.Core.Services.Logger.Info("3班组查询已报工,返回结果:" + JsonConvert.SerializeObject(webResponse));
            return Json(webResponse);
        }

        [HttpPost]
        [Route("GetBanZuYiBaoGongDetail")]
        public ActionResult GetBanZuYiBaoGongDetail([FromBody] Bus_合同分拆报工 bus_合同分拆报工)
        {
            VOL.Core.Services.Logger.Info("1班组查询已报工详细信息,请求:" + JsonConvert.SerializeObject(bus_合同分拆报工));

            WebResponseContent webResponse = new WebResponseContent();
            string message = "";
            Bus_合同分拆报工DTO bus_合同分拆报工dto = _service.GetBanZuYiBaoGongDetail(bus_合同分拆报工);

            if (bus_合同分拆报工dto != null)
            {
                webResponse.Code = "0";
                webResponse.Data = bus_合同分拆报工dto;
            }
            else
            {
                webResponse.Code = "1";
                webResponse.Message = "未查询到数据";
            }
            VOL.Core.Services.Logger.Info("3班组查询已报工详细信息,返回结果:" + JsonConvert.SerializeObject(webResponse));
            return Json(webResponse);
        }

        //删除报工，只能删除当天的报工
        [HttpPost]
        [Route("DeleteBanZuYiBaoGong")]
        public ActionResult DeleteBanZuYiBaoGong([FromBody] Bus_合同分拆报工 bus_合同分拆报工)
        {
            VOL.Core.Services.Logger.Info("1班组删除,请求:" + JsonConvert.SerializeObject(bus_合同分拆报工));
            WebResponseContent webResponse = _service.DeleteBanZuYiBaoGong(bus_合同分拆报工);
            return Json(webResponse);
        }

        [HttpPost]
        [Route("UpdateZiJianBaoGong")]
        public ActionResult UpdateZiJianBaoGong([FromBody] Bus_合同分拆报工DTO 合同分拆报工dtos)
        {
            VOL.Core.Services.Logger.Info("1班组修改报工,请求:" + JsonConvert.SerializeObject(合同分拆报工dtos));

            WebResponseContent webResponse = new WebResponseContent();
            string message = "";
            var a = _service.UpdateZiJianBaoGong(合同分拆报工dtos);
            VOL.Core.Services.Logger.Info("3班组修改报工,返回结果:" + JsonConvert.SerializeObject(a));
            //if (a > 0)
            //{
            //    webResponse.OK(message);
            //}
            //else
            //{
            //    webResponse.Error(message);
            //}

            return Json(a);
        }
        #endregion

        #region 外包报工
        [HttpPost]
        [Route("WaiBaoSubmit")]
        public ActionResult WaiBaoSubmit([FromBody] Bus_合同分拆报工DTO 合同分拆报工dtos)
        {
            VOL.Core.Services.Logger.Info("1外包班组提交报工,请求:" + JsonConvert.SerializeObject(合同分拆报工dtos));

            WebResponseContent webResponse = new WebResponseContent();
            string message = "";
            var a = _service.WaiBaoSubmit(合同分拆报工dtos);
            VOL.Core.Services.Logger.Info("3外包班组提交报工,返回结果:" + JsonConvert.SerializeObject(a));

            return Json(a);
        }

        [HttpPost]
        [Route("GetWaiBaoYiBaoGongList")]
        public ActionResult GetWaiBaoYiBaoGongList([FromBody] Bus_合同分拆报工 bus_合同分拆报工)
        {
            VOL.Core.Services.Logger.Info("1外包班组查询已报工,请求:" + JsonConvert.SerializeObject(bus_合同分拆报工));

            WebResponseContent webResponse = new WebResponseContent();
            string message = "";
            var bus_合同分拆报工List = _service.GetWaiBaoYiBaoGongList(bus_合同分拆报工);

            if (bus_合同分拆报工List != null && bus_合同分拆报工List.Count > 0)
            {
                webResponse.Code = "0";
                webResponse.Data = bus_合同分拆报工List;
            }
            else
            {
                webResponse.Code = "1";
                webResponse.Message = "未查询到数据";
            }
            VOL.Core.Services.Logger.Info("3外包班组查询已报工,返回结果:" + JsonConvert.SerializeObject(webResponse));
            return Json(webResponse);
        }

        [HttpPost]
        [Route("DeleteWaiBaoYiBaoGong")]
        public ActionResult DeleteWaiBaoYiBaoGong([FromBody] Bus_合同分拆报工 bus_合同分拆报工)
        {
            VOL.Core.Services.Logger.Info("1外包班组删除,请求:" + JsonConvert.SerializeObject(bus_合同分拆报工));
            WebResponseContent webResponse = _service.DeleteWaiBaoYiBaoGong(bus_合同分拆报工);
            return Json(webResponse);
        }

        #endregion
    }

}
